//防抖
function debounce(func, delay) {
    let timer = null

    function wrapped(...args) {
        clearTimeout(timer)
        timer = setTimeout(() => {
            return func(...args)
        }, delay)
    }

    return wrapped
}

//节流
function throttle(func, delay) {
    let unlocked = true

    function wrapped(...args) {
        if (unlocked) {
            unlocked = false
            setTimeout(() => {
                unlocked = true
            }, delay)
            return func(...args)
        }

    }

    return wrapped
}

export {debounce, throttle}